<?php
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_routenplaner_routenplaner extends DokuWiki_Syntax_Plugin {

var $l2s_country_names = array(
'Belgien' =>  'BEL',
'Dänemark' => 'DNK',
'Deutschland' => 'DEU',
'Frankreich' => 'FRA',
'Großbritannien' => 'GBR',
'Italien' => 'ITA',
'Liechtenstein' => 'LIE',
'Luxemburg' => 'LUX',
'Niederlande' => 'NLD',
'Norwegen' => 'NOR',
'Österreich' => 'AUT',
'Portugal' => 'PRT',
'Schweden' => 'SWE',
'Schweiz' => 'CHE',
'Spanien' => 'ESP',
'Albanien' =>"ALB",
'Andorra' =>"AND",
'Armenien'=>"ARM",
'Aserbaidschan'=>"AZE",
'Bosnien-Herzegowina'=>"BIH",
'Bulgarien'=>"BGR",
'Estland'=>"EST",
'Faroer Inseln'=>"FRO",
'Finnland'=>"FIN",
'Georgien'=>"GEO",
'Gibraltar'=>"GIB",
'Griechenland'=>"GRC",
'Irland'=>"IRL",
'Island'=>"ISL",
'Kroatien'=>"HRV",
'Lettland'=>"LVA",
'Litauen'=>"LTU",
'Malta'=>"MLT",
'Makedonien'=>"MKD",
'Moldawien'=>"MDA",
'Monaco'=>"MCO",
'Polen'=>"POL",
'Rumänien'=>"ROM",
'Russland'=>"RUS",
'San Marino'=>"SMR",
'Serbien und Montenegro'=>"SCG",
'Slowakische Republik'=>"SVK",
'Slowenien'=>"SVN",
'Tschechische Republik'=>"CZE",
'Türkei'=>"TUR",
'Ukraine'=>"UKR",
'Ungarn'=>"HUN",
'Vatikanstadt'=>"VAT",
'Weißrussland'=>"BLR",
'Zypern'=>"CYP"
);
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Deshi, Jaloma',
            'email'  => 'deshi@web.de, jaloma.ac@googlemail.com',
            'date'   => '17/10/2008',
            'name'   => 'Routenplaner Plugin',
            'desc'   => 'plan your route using lycos or web.de',
		 'url'    => 'http://jaloma.ac.googlepages.com/plugin:routenplaner'
        );
    }
 
    /**
     * Syntax-Beispiel: {{routeplaner> Hubert Meier, Mustergasse 3, 80756, München, Deutschland}}
     */
 
 
/**
 * Plugin Type
 */
 
 	function getType(){ return 'substition'; }
 	function getSort(){ return 314; }
 	function connectTo($mode) { $this->Lexer->addSpecialPattern("\{\{routenplaner>.*?\}\}",$mode,'plugin_routenplaner_routenplaner'); }
 
 
function matchLength() {
 return 15;
 }

/**
 * Handle the match
 */
 
    function handle($match, $state, $pos, &$handler){
 
        // strip markup
		//12345678901234567890123
		//{{routenplaner>
		//{{routenplaner_webde>
		//{{routenplaner_lycosde>
        $match = html_entity_decode(substr($match,$this->matchLength(),-2));
 
        // split into pieces
        list($company,$street,$zip, $town, $country) = explode(',',$match,5);
 
        // beautify strings
        if (trim($company, " \t\n") != '') {
        	$company = trim($company, " \t\n");
        } else {
        	$company = 'Firma';
        }
        if (trim($street, " \t\n") != '') {
        	$street = trim($street, " \t\n");
        } else {
        	$street = ' ';//missing street';
        }
        if (trim($zip, " \t\n") != '') {
        	$zip = trim($zip, " \t\n");
        } else {
        	$zip = ' ';//'missing zip';
        }
        if (trim($town, " \t\n") != '') {
        	$town = trim($town, " \t\n");
        } else {
        	$town = ' ';//'missing town';
        }
        if (trim($country, " \t\n") != '') {
        	$country = trim($country, " \t\n");
        } else {
        	$country = ' ';//'missing country';
        }
 
        return array($company,$street,$zip,$town,$country);
    }
 
 
/**
 * Create output
 */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= $this->_contact($data);
            return true;
        }
        return false;
    }
 
/**
 * Does the contact form xhtml creation. Adds some javascript to validate the form
 * and creates the input form.
 */
 
 
    /**
     * Does the contact form xhtml creation. Adds some javascript to validate the form
     * and creates the input form.
     */
    function _contact($data){
    	if ($this->getConf('modus') == 'lycosde') {
    		return $this->lycosDeFormular($data);
    	} elseif ($this->getConf('modus') == 'webde') {
    		return $this->webDeFormular($data);
    	} else {
        return 'Modus nicht unterstützt';
      }
    }
	
	function lycosDeFormular($data) {
		$company = $data[0];
		@$street = $data[1];
		@$zip = $data[2];
		@$town = $data[3];
		@$country = $data[4];
        $ret = '';
 
//        $ret .= '<script type="text/javascript"></script>';
        $ret .= '<div class="columns1">';
        $ret .= '<form name="routenplaner2" method="get" target="_blank" action="http://www.lycos.de/routenplaner/index.html">';
        $ret .= '<input type="hidden" name="tocountry" value="'.$this->l2s_country_names[$country].'" />';
        $ret .= '<input type="hidden" name="tostreet" value="'.$street.'" />';
        $ret .= '<input type="hidden" name="toplz" value="'.$zip.'" />';
        $ret .= '<input type="hidden" name="tocity" value="'.$town.'" />';
        $ret .= '<table border="0" cellpadding="0" cellspacing="0" style="background-image:url(http://www.lycos.de/i/c/reise/routenplaner/box_partner.gif);background-repeat:no-repeat;width:379px;height:176px;"><tr><td><br>';
        $ret .= '<table border="0" cellpadding="0" cellspacing="0" style="margin-left:15px;padding: 0px 0px 0px 0px;font: 12px "Trebuchet MS", Tahoma, Geneva, Arial, Helvetica, sans-serif;color: #000;">';
        $ret .= '<tr>';
        $ret .= '<td width="47%"> </td>';
        $ret .= '<td width="6%"> </td>';
        $ret .= '<td width="47%"><strong>Ziel:</strong></td>';
        $ret .= '</tr>';
        $ret .= '<tr>';
        $ret .= '<td width="47%"><strong>Start:</strong></td>';
        $ret .= '<td width="6%"> </td>';
        $ret .= '<td width="47%"><input type="text" name="toname_" value="'.$company.'" disabled="disabled" style="width:155px;" /></td>';
        $ret .= '</tr>';
        $ret .= '<tr>';
        $ret .= '<td><input type="TEXT" name="fromstreet" value="Straße" size="12" style="width: 155px;" tabindex="1" onfocus="javascript:if (document.routenplaner.fromstreet.value == '."'".'Straße'."'".') document.routenplaner.fromstreet.value = '."''".';"></td>';
        $ret .= '<td> </td>';
        $ret .= '<td><input type="TEXT" name="tostreet_" value="'.$street.'" size="12" style="width: 155px;" tabindex="5" disabled="disabled" /></td>';
        $ret .= '</tr>';
        $ret .= '<tr>';
        $ret .= '<td><input type="TEXT" name="fromplz" value="PLZ" size="5" style="width: 45px;"  maxlength="10" tabindex="2" onfocus="javascript:if (document.routenplaner.fromplz.value == '."'".'PLZ'."'".') document.routenplaner.fromplz.value = '."''".';"> ';
        $ret .= '<input type="TEXT" name="fromcity" value="Ort" size="8" style="width: 101px;" tabindex="3" onfocus="javascript:if (document.routenplaner.fromcity.value == '."'".'Ort'."'".') document.routenplaner.fromcity.value = '."''".';"></td>';
        $ret .= '<td></td>';
        $ret .= '<td><input type="TEXT" name="toplz_" value="'.$zip.'" tabindex="6" size="5" style="width: 45px;"  maxlength="10" disabled="disabled" /> ';
        $ret .= '<input type="TEXT" name="tocity_" value="'.$town.'" tabindex="7" size="8" style="width: 101px;" disabled="disabled" /></td>';
        $ret .= '</tr>';
        $ret .= '<tr>';
        $ret .= '<td><select name="fromcountry" tabindex="4" style="width:155px;">';
        $ret .= '	<option value="---">Bitte wählen...</option>';
        $ret .= '	<option value="BEL">Belgien</option>';
        $ret .= '	<option value="DNK">Dänemark</option>';
        $ret .= '	<option value="DEU" selected="selected">Deutschland</option>';
        $ret .= '	<option value="FRA">Frankreich</option>';
        $ret .= '	<option value="GBR">Großbritannien</option>';
        $ret .= '	<option value="ITA">Italien</option>';
        $ret .= '	<option value="LIE">Liechtenstein</option>';
        $ret .= '	<option value="LUX">Luxemburg</option>';
        $ret .= '	<option value="NLD">Niederlande</option>';
        $ret .= '	<option value="NOR">Norwegen</option>';
        $ret .= '	<option value="AUT">Österreich</option>';
        $ret .= '	<option value="PRT">Portugal</option>';
        $ret .= '	<option value="SWE">Schweden</option>';
        $ret .= '	<option value="CHE">Schweiz</option>';
        $ret .= '	<option value="ESP">Spanien</option>';
        $ret .= '</select>';
        $ret .= '</td>';
        $ret .= '<td></td>';
        $ret .= '<td><input type="text" name="tocountry_" value="'.$country.'" disabled="disabled" style="width:155px;" /></td>';
        $ret .= '</tr>';
        $ret .= '<tr>';
        $ret .= '	<td colspan="3" align="right" style="float:right;"><div class="button" style="width:110px;text-align:center;float:right;margin-top:5px;"><div class="btnleft"></div><div class="btncenter" style="width:90px;text-align:center;"><input type="Submit" value="Berechnen"></div><div class="btnright"></div><div class="breaker"></div></div></td>';
        $ret .= '</tr>';
        $ret .= '</table>';
        $ret .= '</td></tr></table></form>';
        $ret .= '<div class="breaker"></div>';
        $ret .= '</div>';
 
        return $ret;
    }
        
    function webDeFormular($data) {
		@$company = $data[0];
		@$street = $data[1];
		@$zip = $data[2];
		@$town = $data[3];
		@$country = $data[4];
		$txt .='<form id="route" method="get" target="_blank" action="http://iww.web.de/de/themen/auto/routenplaner/">';
		$txt .='<table cellpadding="0" cellspacing="0" style="background: #FFF url(http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_hg.gif) bottom left no-repeat; width: 461px;">';
		$txt .='<tr>';
		$txt .='<td style="vertical-align: top;"><img src="http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_oben.gif" alt="" style="margin: 0;"></td>';
		$txt .='</tr>';
		$txt .='<tr>';
		$txt .='<td style="vertical-align: top;"><img src="http://iww.web.de/de/themen/auto/routenplaner/img/webde_rp_balkon_icon.gif" alt="" style="margin: 0;"></td>';
		$txt .='</tr>';
		$txt .='<tr>';
		$txt .='<td>';
		$txt .='<table style="border: 1px solid #D8DFE5; border-top: none; border-bottom: none; margin-bottom: 3px; width: 100%;">';
		$txt .='<tr>';
		$txt .='<td style="width: 50%;">';
		$txt .='<input id="fromstreet" name="fromstreet" value="Straße" size="12" style="font-size: 12px; width: 206px; margin: 5px 5px 0 10px;" tabindex="1" onfocus="if (this.value == '."'Straße'".') this.value = '."''".';" type="text" /><br/>';
		$txt .='<input id="fromplz" name="fromplz" value="PLZ" size="2" style="font-size: 12px; vertical-align: top; width: 47px; margin: 5px 5px 0 10px;" maxlength="10" tabindex="2" onfocus="if (this.value == '."'PLZ'".') this.value = '."''".';" type="text" />';
		$txt .='<input id="fromcity" name="fromcity" value="Ort" size="8" style="font-size: 12px; width: 144px; margin-top: 5px;" tabindex="3" onfocus="if (this.value == '."'Ort'".') this.value = '."''".';" type="text" /><br/>';
		$txt .='<select id="fromcountry" name="fromcountry" tabindex="4" style="font-size: 12px; width: 212px; margin: 5px 9px 0 10px;">';
		$txt .='<option value="---">Bitte wählen...</option>';
		$txt .='<option value="ALB">Albanien</option>';
		$txt .='<option value="AND">Andorra</option>';
		$txt .=' 			<option value="ARM">Armenien</option>';
		$txt .=' 			<option value="AZE">Aserbaidschan</option>';
		$txt .=' 			<option value="BEL">Belgien</option>';
		$txt .=' 			<option value="BIH">Bosnien-Herzegowina</option>';
		$txt .=' 			<option value="BGR">Bulgarien</option>';
		$txt .=' 			<option value="DNK">Dänemark</option>';
		$txt .=' 			<option value="DEU" selected="selected">Deutschland</option>';
		$txt .=' 			<option value="EST">Estland</option>';
		$txt .=' 			<option value="FRO">Faroer Inseln</option>';
		$txt .=' 			<option value="FIN">Finnland</option>';
		$txt .=' 			<option value="FRA">Frankreich</option>';
		$txt .=' 			<option value="GEO">Georgien</option>';
		$txt .=' 			<option value="GIB">Gibraltar</option>';
		$txt .=' 			<option value="GRC">Griechenland</option>';
		$txt .=' 			<option value="GBR">Großbritannien</option>';
		$txt .=' 			<option value="IRL">Irland</option>';
		$txt .=' 			<option value="ISL">Island</option>';
		$txt .=' 			<option value="ITA">Italien</option>';
		$txt .=' 			<option value="HRV">Kroatien</option>';
		$txt .=' 			<option value="LVA">Lettland</option>';
		$txt .=' 			<option value="LIE">Liechtenstein</option>';
		$txt .=' 			<option value="LTU">Litauen</option>';
		$txt .=' 			<option value="LUX">Luxemburg</option>';
		$txt .=' 			<option value="MLT">Malta</option>';
		$txt .=' 			<option value="MKD">Makedonien</option>';
		$txt .=' 			<option value="MDA">Moldawien</option>';
		$txt .=' 			<option value="MCO">Monaco</option>';
		$txt .=' 			<option value="NLD">Niederlande</option>';
		$txt .=' 			<option value="NOR">Norwegen</option>';
		$txt .=' 			<option value="AUT">Österreich</option>';
		$txt .=' 			<option value="POL">Polen</option>';
		$txt .=' 			<option value="PRT">Portugal</option>';
		$txt .=' 			<option value="ROM">Rumänien</option>';
		$txt .=' 			<option value="RUS">Russland</option>';
		$txt .=' 			<option value="SMR">San Marino</option>';
		$txt .=' 			<option value="SWE">Schweden</option>';
		$txt .=' 			<option value="CHE">Schweiz</option>';
		$txt .=' 			<option value="SCG">Serbien und Montenegro</option>';
		$txt .=' 			<option value="SVK">Slowakische Republik</option>';
		$txt .=' 			<option value="SVN">Slowenien</option>';
		$txt .=' 			<option value="ESP">Spanien</option>';
		$txt .=' 			<option value="CZE">Tschechische Republik</option>';
		$txt .=' 			<option value="TUR">Türkei</option>';
		$txt .=' 			<option value="UKR">Ukraine</option>';
		$txt .=' 			<option value="HUN">Ungarn</option>';
		$txt .=' 			<option value="VAT">Vatikanstadt</option>';
		$txt .=' 			<option value="BLR">Weißrussland</option>';
		$txt .=' 			<option value="CYP">Zypern</option>';
		$txt .=' 		</select>';
		$txt .=' 	</td>';
		$txt .=' 	<td>';
		$txt .='';
		$txt .=' 		<input id="tostreet" name="tostreet" value="'.$street.'" type="hidden">';
		$txt .=' 		<input id="toplz" name="toplz" value="'.$zip.'" size="3" type="hidden">';
		$txt .=' 		<input id="tocity" name="tocity" value="'.$town.'" size="8" type="hidden">';
		$txt .=' 		<input id="tocountry" name="tocountry" type="hidden" value="'.$this->l2s_country_names[$country].'">';
		$txt .=' 		<p style="font-size: 12px; font-weight: 700; margin: 0 5px !important;"></p>';
		$txt .=' 		<p style="font-size: 12px; margin: 8px 5px !important;">'.$street.'</p>';
		$txt .=' 		<p style="font-size: 12px; margin: 0 5px !important;">'.$country.' - '.$zip.' '.$town.'</p>';
		$txt .='';
		$txt .=' 	</td>';
		$txt .=' </tr>';
		$txt .=' <tr>';
		$txt .=' 	<td colspan="2"><input id="planer" type="hidden" value="" /></td>';
		$txt .=' </tr>';
		$txt .=' <tr>';
		$txt .=' 	<td colspan="2" style="text-align: center;"><input type="submit" value="Route berechnen" style="margin: 5px 0; font-size: 11px !important;" /></td>';
		$txt .=' </tr>';
		if ($this->getConf('showwebdefooter') == true) {
		$txt .=' <tr>';
		$txt .=' 	<td colspan="2" style="font-size: 11px;">Der WEB.DE <a href="http://iww.web.de/de/themen/auto/routenplaner/index.wjsp">Routenplaner</a> auch auf Ihrer <a href="http://iww.web.de/de/themen/auto/routenplaner/freiesrouting.wjsp">Homepage</a></td>';
		$txt .=' </tr>';
		}
		$txt .='	</table>';
		$txt .='  </td>';
		$txt .='</tr>';
		$txt .='</table>';
		$txt .='</form>';
        return $txt;
} // Function

} // CLASS

